/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.stefanini.mundial2014.ejbs;

import com.stefanini.persitencia.Usuario;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Lady
 */
@LocalBean
@Stateless
public class UserManagement {
    @PersistenceContext
    private EntityManager em;
    
    public Usuario verificarLogin(String usuario, String password){
        try {
            StringBuilder query = new StringBuilder();
            query.append("SELECT u FROM Usuario u ");
            query.append("WHERE u.username=:USERNAME ");
            query.append("AND u.password =:PASSWORD");  
            
           Query q = em.createQuery(query.toString(),Usuario.class);
           q.setParameter("USERNAME",  usuario);
           q.setParameter("PASSWORD", password);
           return(Usuario)q.getSingleResult();//retorna algo en la B.D
        } catch (Exception e) {
            Logger.getLogger(UserManagement.class.getName()).log(Level.SEVERE,
                    "Error al verificar el login",e);
        }
     return null;   
    }  
    
}
